﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:Converters="clr-namespace:GraphLight.Converters"
        xmlns:Drawing="clr-namespace:GraphLight.Drawing">

    <ControlTemplate x:Key="edgeTemplate" TargetType="Drawing:Edge">
        <Grid Background="{x:Null}">
            <Grid.Resources>
                <Converters:PointsToQuadraticBezierConverter x:Key="bezierConverter" />
            </Grid.Resources>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="SelectedStates">
                    <VisualState x:Name="SelectionOn">
                        <Storyboard>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="SelectionOff" />
                </VisualStateGroup>
                <VisualStateGroup x:Name="HighlightedStates">
                    <VisualState x:Name="HighlightOn">
                        <Storyboard>
                            <ColorAnimation To="Red" Duration="00:00:00" Storyboard.TargetName="arrow"
                                    Storyboard.TargetProperty="(Stroke).(SolidColorBrush.Color)" />
                            <DoubleAnimation Storyboard.TargetName="arrow" Duration="00:00:00"
                                    Storyboard.TargetProperty="StrokeThickness" To="3" />
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="HighlightOff" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <i:Interaction.Behaviors>
                <ei:DataStateBehavior Value="True" TrueState="SelectionOn" FalseState="SelectionOff"
                        Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                <ei:DataStateBehavior Value="True" TrueState="HighlightOn" FalseState="HighlightOff"
                        Binding="{Binding Path=IsHighlighted, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
            </i:Interaction.Behaviors>
            <Path x:Name="arrow" StrokeThickness="{Binding Thickness}" Stroke="{Binding StrokeBrush}"
                    Data="{Binding Data.Points, Converter={StaticResource bezierConverter}}" />
        </Grid>
    </ControlTemplate>

    <Style TargetType="Drawing:Edge">
        <Setter Property="Canvas.ZIndex" Value="{Binding Data.ZIndex}" />
        <Setter Property="IsSelected" Value="{Binding Data.IsSelected}" />
        <Setter Property="IsHighlighted" Value="{Binding Data.IsHighlighted}" />
        <Setter Property="Template" Value="{StaticResource edgeTemplate}" />
    </Style>

</ResourceDictionary>